package server;


import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;

import javax.imageio.ImageIO;



import ocsf.server.ConnectionToClient;
import sharedspace.*;

import database.*;
import messages.*;
import messages.MessageExecuteExamCodeCheckReply.ErrMsg;



/**
 * This class Responsible to assign tasks to the server according to the Message it gets
 * from the Client
 * 
 * @author Amir S.
 * @author Jacob C.
 * @author Maya G.
 * @author Michael V.
 *
 */

public class TaskAssignment {
	
	/**
	 * 
	 * @param msg - The message to be dealt with
	 * @param client - The client who sent the message
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @throws SQLException
	 * @throws IOException
	 */
	
	public TaskAssignment(Object msg,ConnectionToClient client) throws IllegalArgumentException, IllegalAccessException, SQLException, IOException
	{
		Message baseMessage = (Message) msg;
		switch (baseMessage.getMessageType()){
			case MESSAGE_LOGIN :
			{
				
				// check if username and pass are correct in database
				   //and send back corresponding message
				   MessageLogin MsgLog=(MessageLogin) baseMessage;
				   
			   try {
				    LoginCheck logC=new LoginCheck(MsgLog.getUser());
				    logC.Check();
				    MessageLoginReply reply = new MessageLoginReply(logC.getUser(),logC.getErrorMessage());
				    client.sendToClient(reply);
				    //logC.jdbc.connection.close();
				   } catch (IOException e) {
				 
				    e.printStackTrace();
				   }
				   
			 } 
			break;
				  
			
				
			case MESSAGE_LOGOUT:
			{
				MessageLogout MsgLog=(MessageLogout) baseMessage;
				
				LogOut logout = new LogOut(MsgLog.getUserID(), MsgLog.getNum());
				
				logout.makeLogOut();
				
				MessageLogoutReply reply = new MessageLogoutReply(logout.getLogoutStatus(), logout.getErrorMsg());
				
				client.sendToClient(reply);
				
			}
			break;
				
			case MESSAGE_LOG_EVERYONE_OUT:
			{
				MessageLogEveryoneOut MsgLog = (MessageLogEveryoneOut)baseMessage;
				LogOut logout = new LogOut();	
				logout.makeLogEveryoneOut();
				client.sendToClient("Logged Everyone Out");
				
			}
			break;
			
			case MESSAGE_GET_STUDENT:
			{
				MessageStudent msgStd = (MessageStudent)baseMessage;
				String studentId = msgStd.getStudent().getUserID();
				StudentControl sCtrl = new StudentControl();
				ExecuteTestControl eCtrl = new ExecuteTestControl(); 
				CourseControl cCtrl = new CourseControl();
				List<ExecuteTest> eList = new ArrayList<ExecuteTest>();
				List<Executetestinfo> eiList = new ArrayList<Executetestinfo>();
				Student student = sCtrl.getStudentByStudentID(studentId);
				List<Course> cList = cCtrl.getCourseListByStudentID(student.getUserID(), DateUtils.currentYear(), DateUtils.currentSemester());
				for (int i = 0; i<cList.size();i++)
					eList.addAll(eCtrl.getExecuteTestListByCourseID(cList.get(i).getCourseID(), DateUtils.currentYear(), DateUtils.currentSemester()));
				
				for (int i = eList.size()-1; i>=0; i--)
					if (eList.get(i).getTestStatus()==false)
						eList.remove(i);
				for (int i = 0; i<eList.size(); i++)
					eiList.add(eCtrl.getExecutetestinfo(eList.get(i).getExecuteTestID()));
				
				
				msgStd.setStudent(student);
				msgStd.seteList(eList);
				msgStd.setEiList(eiList);
				client.sendToClient(msgStd);
			}
			break;
			case MESSAGE_EXECUTE_EXAM_CHECK_CODE:
			{
				MessageExecuteExamCheckCode MsgEebs = (MessageExecuteExamCheckCode) baseMessage;
				System.out.println(MsgEebs.getExamCode() + " " + MsgEebs.getStudent().getUserFirstName());
			    ExecuteExamByStudent eebs = new ExecuteExamByStudent(MsgEebs.getStudent(), MsgEebs.getExamCode());
				eebs.checkCodeTest(); 
				MessageExecuteExamCodeCheckReply Reply = new MessageExecuteExamCodeCheckReply(eebs.getErrorMessage(),MsgEebs.getStudent(),eebs.getExecuteTest());
				client.sendToClient(Reply);	
			}
				break;
			case MESSAGE_EXECUTE_EXAM_GET_EXAM:
			{
				MessageExecuteExamGetExam MsgEege = (MessageExecuteExamGetExam)baseMessage;
				ExecuteExamByStudent eebs = new ExecuteExamByStudent(MsgEege.getExecuteTest());
				List<QuestionInTest> questionInTestList = eebs.getExam();
				Course course = (new CourseControl()).getCourseByTestID(eebs.getExecuteTest().getTest().getTestID());
				MessageExecuteExamGetExamReply Reply = new MessageExecuteExamGetExamReply(questionInTestList, course);
				client.sendToClient(Reply);
			}
			break;
			case MESSAGE_GET_SUBJECT:
			{
				MessageSubject MsgTiS = (MessageSubject) baseMessage;	
				 SubjectControl subjectC=new SubjectControl ();
				 ArrayList <Subject>list = new ArrayList<Subject>();
				 list=(ArrayList<Subject>) (subjectC.getSubjectList());
				 MessageSubjectReply reply=new MessageSubjectReply(list);
				 client.sendToClient(reply);
				
			}
			break;
			case MESSAGE_GET_ALL_QUESTIONS:
			{
				MessageAllQuestions MsgTiS = (MessageAllQuestions) baseMessage;
				 QuestionControl QuestionC=new QuestionControl ();
				 ArrayList <Question>list = new ArrayList<Question>();
				 list=(ArrayList<Question>) (QuestionC.getQuestionList());
				 MessageAllQuestionsReply reply=new MessageAllQuestionsReply(list);
				 client.sendToClient(reply);	
				 
			}
			break;
			case MESSAGE_GET_QUESTION_LIST_BY_TESTID:
			{
				MessageQuestionListByTestID MsgGql =(MessageQuestionListByTestID)baseMessage;
				 QuestionControl qc=new QuestionControl ();
				 List<QuestionInTest>list = new ArrayList<QuestionInTest>();
				 list=qc.getQuestionListByTestID(MsgGql.getTestID());
				 client.sendToClient(list);
				
			}
			break;
			case MESSAGE_GET_ALL_COURSES:
			{
				 CourseControl cc=new CourseControl();
				 List<Course> list = new ArrayList<Course>();
				 list=cc.getCourseList();
				 client.sendToClient(list);	
				
			}
			break;
			case MESSAGE_GET_ALL_EXAMS:
			{
				 TestControl tc=new TestControl();
				 List<Test> list = new ArrayList<Test>();
				 list=tc.getTestList();
				 client.sendToClient(list);	
				
			}
			break;
			case MESSAGE_GET_ALL_EXECUTE_EXAMS:
			{
				 ExecuteTestControl etc=new ExecuteTestControl();
				 List<ExecuteTest> list = new ArrayList<ExecuteTest>();
				 list=etc.getExecutedTestList();
				 client.sendToClient(list);	
				
			}
			break;
			case MESSAGE_GET_TEACHER:
			{
				MessageTeacher MsgTiS = (MessageTeacher) baseMessage;		
				 TeacherControl teacherC=new TeacherControl ();
				 ArrayList<Teacher>list = new ArrayList<Teacher>();
				 list=(ArrayList<Teacher>) (teacherC.getTeacherList());
				 MessageTeacherReply reply=new MessageTeacherReply(list);
				 client.sendToClient(reply);
				
			}
			break;	
			case MESSAGE_GET_TEACHER_SUBJECT:
			{
				MessageTeacherSubject MsgTiS = (MessageTeacherSubject) baseMessage;		
				List<Subject> list = new ArrayList<Subject>();
				SubjectControl sc = new SubjectControl();
				list = sc.getSubjectListByTeacherID(MsgTiS.getUser().getUserID());		
				client.sendToClient(list);
				
			}
			break;
			
			case MESSAGE_MANAGE_QUESTION:
			{
				
				MessageManageQuestion MsgAddQ = (MessageManageQuestion)baseMessage;
				ManageQuestion manageQuestion= new ManageQuestion(MsgAddQ.getQuestion());
				manageQuestion.addQuestion();
				String added=manageQuestion.getQuestion().getQuestionID();
				System.out.println(""+added);
				client.sendToClient(added);
			}
			break;
			
			case MESSAGE_GET_COURSE_IN_SUBJECT:
			{
				MessageCourse MsgCiS = (MessageCourse) baseMessage;
				 CourseControl courseC=new CourseControl ();				
				 List<Course> list=courseC.getCourseListBySubjectID(MsgCiS.getSubjectID());
				 client.sendToClient(list);	
				
			}
			break;
			case MESSAGE_START_TIME:
			{
				MessageStartTime MsgSt = (MessageStartTime)baseMessage;
				ExecuteExamByStudent eebs = new ExecuteExamByStudent(MsgSt.getExecuteTestID(),MsgSt.getStudentID());
				eebs.startClock();
				
				
			}
			break;
			case MESSAGE_QUESTION_UPDATE:
			{
				MessageQuestionUpdate MsgQu = (MessageQuestionUpdate)baseMessage;
				QuestionControl qu = new QuestionControl();
				qu.updateQuestion(MsgQu.getQuestion());	
			}
			break;

			case MESSAGE_STUDENT_IN_TEST:
			{
				MessageStudentInTest MsgSit = (MessageStudentInTest)baseMessage;
				ExecuteExamByStudent eebs = new ExecuteExamByStudent(MsgSit.getStudentInTest(), MsgSit.getExecuteTest());
				eebs.updateStudentStart();
			}
			break;
			
			case MESSAGE_SUMBIT_TEST_CHOICES:
			{
				MessageSumbitTestChoices MsgStc = (MessageSumbitTestChoices)baseMessage;
				ExecuteExamByStudent eebs = new ExecuteExamByStudent(MsgStc.getTeacherID(), MsgStc.getChoicesList(), MsgStc.getEndTime());
				eebs.setAnswers();
				/***************************************************************************************************/
				
			}
			break;
		
			case MESSAGE_EXTRA_TIME_CHECK:
			{
				MessageExtraTimeCheck MsgEtc = (MessageExtraTimeCheck)baseMessage;
				ExecuteExamByStudent eebs= new ExecuteExamByStudent();
				MessageExtraTimeCheckReply reply; 
				reply = eebs.checkExtraTime(MsgEtc);
				client.sendToClient(reply);
			}
			break;
			case MESSAGE_STUDENTS_BY_EXECUTETESTID:
			{
				MessageStudentListByExam MsgSiE = (MessageStudentListByExam) baseMessage;	
				StudentControl studentC = new StudentControl(); 
				List <StudentInTest> list=studentC.getStudentListByExecuteTestID(MsgSiE.getExecuteTestID());
				client.sendToClient(list);
				
			}
			break;
			case MESSAGE_QUESTIONS_BY_SUBJECT:
			{	
				MessageQuestionBySubject MsgQiS = (MessageQuestionBySubject) baseMessage;	
				QuestionControl questionC = new QuestionControl (); 
				List <Question> list=questionC.getQuestionListBySubjectID(MsgQiS.getSubjectID());
				client.sendToClient(list);
				
			}
			break;
			case MESSAGE_APPROVED_TEST:
			{
				MessageApprovedTest MsgAt = (MessageApprovedTest) baseMessage;
				ApprovingComputerizedTestGrade actg = new ApprovingComputerizedTestGrade(MsgAt.getTeacherID());
				List<ApprovingGrade> aList = actg.getApprovedTest();
				MessageApprovedTestReply reply = new MessageApprovedTestReply(aList);
				client.sendToClient(reply);
				
			}
			break;
			case MESSAGE_APPROVED_TEST_BY_EXECUTE_TEST:
			{
				MessageApprovedTestByExecuteTest MsgAtE = (MessageApprovedTestByExecuteTest) baseMessage;
				StudentControl actge = new StudentControl();
				List<ApprovingGrade> aList = actge.getApprovedGradeByExecuteTestID(MsgAtE.getExecuteTestID());
				MessageApprovedTestByExecuteTestReply reply = new MessageApprovedTestByExecuteTestReply(aList);
				client.sendToClient(reply);
			}
			break;
			case MESSAGE_FINAL_GRADE:
			{
				MessageFinalGrade MsgFg = (MessageFinalGrade) baseMessage;
				ApprovingComputerizedTestGrade actg = new ApprovingComputerizedTestGrade(MsgFg.getApprovingGrade());
				actg.updateFinalGradeComputerized();
				actg.setStatisticInformation();
			}
			break;
			case MESSAGE_GET_QUESTION_LIST_BY_TEACHERID:
			{
				MessageQuestionListByTeacherID MsgGql = (MessageQuestionListByTeacherID) baseMessage;
				QuestionControl qc = new QuestionControl();
				List<Question> list = new ArrayList<Question>();
				list = qc.getQuestionListByAuthor(MsgGql.getTeacherID(), false);
				client.sendToClient(list);
			
			}
			break;
			case MESSAGE_GET_STUDENT_GRADE:
			{
				MessageStudentGrades MsgSg = (MessageStudentGrades) baseMessage;
				StudentControl stCtrl = new StudentControl();
				List<ApprovingGrade> gList = stCtrl.getApprovedGradeByStudentID(MsgSg.getStudetn().getUserID());
				MessageStudentGradesReply reply = new MessageStudentGradesReply(gList);
				client.sendToClient(reply);
			}
			break;
			
			
			case MESSAGE_ALLOCATE_TEST_ID:
			{	
				MessageAllocateTestId  MsgQiS = (MessageAllocateTestId ) baseMessage;	
				TestControl testC = new TestControl (); 
				
				String a=testC.AllocationTest(MsgQiS.getSujectID(),MsgQiS.getCourseID(),MsgQiS.getTest());
				client.sendToClient(a);	
			}
			break;
		
			case MESSAGE_SAVE_QUESTION_TEST:
			{
				MessageSaveQuestionsTest MsgQiT= (MessageSaveQuestionsTest) baseMessage;
				QuestionControl Qtest=new QuestionControl();
				Qtest.insertQuestionInTest(MsgQiT.getQuesInTest());
				Qtest.updateInUseQuestoin(MsgQiT.getQuesInTest());
			}
			break;
			
			case MESSAGE_TEACHER_EXAM:
			{
				MessageTeacherExecuteTest MsgTet = (MessageTeacherExecuteTest) baseMessage;
				ExecuteTestControl e = new ExecuteTestControl();
				List<ExecuteTest> eList = e.getExecuteTestListByTeacherID(MsgTet.getTeacherID());
				int originSize = eList.size();
				for (int i = originSize-1 ; i>=0; i--)
					if (eList.get(i).getTestStatus() == false)
						eList.remove(i);
				MessageTeacherExecuteTestReply  reply= new MessageTeacherExecuteTestReply(eList);
				client.sendToClient(reply);
			}
		
			break;
			
			case MESSAGE_GET_TEACHER_COURSE_SEMESTER:
			{
				MessageCoursesOfTeacher MsgCoT= (MessageCoursesOfTeacher) baseMessage;
				CourseControl courseC=new CourseControl();
				List<Course> cList=courseC.getCourseListByTeacherID(MsgCoT.getTeacher().getUserID(),MsgCoT.getYear(),MsgCoT.getSemester());
				client.sendToClient(cList);	
			}
			break;
			
			case MESSAGE_TEST_LOCK:
			{
				MessageLockTest MsgLt = (MessageLockTest) baseMessage;
				JDBC.updateStatmentCloumn("executetest e", "e.testStatue", "false", "e.executeTestID='"+MsgLt.getExecuteTestID()+"'");
			}
			break;
			
			case MESSAGE_GET_EXECUTED_EXAM_LIST_BY_TEACHERID:
			{
				MessageExecutedExamListByTeacherID msgGel = (MessageExecutedExamListByTeacherID)baseMessage;
				ExecuteTestControl etc = new ExecuteTestControl();
				List<ExecuteTest> exList = new ArrayList<ExecuteTest>();
				List<Executetestinfo> exInfoList = new ArrayList<Executetestinfo>();
				exList = etc.getExecuteTestListByTeacherID(msgGel.getTeacherID());
				for (int i = 0; i<exList.size(); i++)
					exInfoList.add(etc.getExecutetestinfo(exList.get(i).getExecuteTestID()));
				MessageExecutedExamListReply reply = new MessageExecutedExamListReply(exList,exInfoList);
				client.sendToClient(reply);
			}
			break;
			case MESSAGE_GET_EXECUTED_EXAM_LIST_BY_AUTHORID:
			{
				MessageExecutedExamListByAuthorID msgGel = (MessageExecutedExamListByAuthorID)baseMessage;
				ExecuteTestControl etc = new ExecuteTestControl();
				List<ExecuteTest> exList = new ArrayList<ExecuteTest>();
				List<Executetestinfo> exInfoList = new ArrayList<Executetestinfo>();
				exList = etc.getExecuteTestListByTeacherID(msgGel.getAuthorID());
				for (int i = 0; i<exList.size(); i++)
				{	
					if((exList.get(i).getTest().getAuthor().getUserID()).equals(msgGel.getAuthorID()))
						exInfoList.add(etc.getExecutetestinfo(exList.get(i).getExecuteTestID()));
				}
				MessageExecutedExamListReply reply = new MessageExecutedExamListReply(exList,exInfoList);
				client.sendToClient(reply);
			}
			break;
			
			case MESSAGE_GET_EXECUTED_EXAM_LIST_BY_STUDENTID:
			{
				MessageExecutedExamListByStudentID msgGsid = (MessageExecutedExamListByStudentID)baseMessage;
				ExecuteTestControl etc = new ExecuteTestControl();
				List<ExecuteTest> exList = new ArrayList<ExecuteTest>();
				List<Executetestinfo> exInfoList = new ArrayList<Executetestinfo>();
				exList = etc.getExecuteTestByStudentID(msgGsid.getStudentID());
				for (int i = 0; i<exList.size(); i++)
					exInfoList.add(etc.getExecutetestinfo(exList.get(i).getExecuteTestID()));
				MessageExecutedExamListReply reply = new MessageExecutedExamListReply(exList,exInfoList);
				client.sendToClient(reply);
			}
			break;
			
			case MESSAGE_GET_EXECUTED_EXAM_LIST_BY_COURSEID:
			{
				MessageExecutedExamListByCourseID msgGsid = (MessageExecutedExamListByCourseID)baseMessage;
				ExecuteTestControl etc = new ExecuteTestControl();
				List<ExecuteTest> exList = new ArrayList<ExecuteTest>();
				List<Executetestinfo> exInfoList = new ArrayList<Executetestinfo>();
				exList = etc.getExecuteTestListByCourseID(msgGsid.getCourseID());
				for (int i = 0; i<exList.size(); i++)
					exInfoList.add(etc.getExecutetestinfo(exList.get(i).getExecuteTestID()));
				MessageExecutedExamListReply reply = new MessageExecutedExamListReply(exList,exInfoList);
				client.sendToClient(reply);
			}
			break;
			
			case MESSAGE_GET_EXAM_BY_COURSEID:
			{
				MessageExamOfCourse msgGel = (MessageExamOfCourse)baseMessage;
				TestControl testC = new TestControl();
				List<Test> exList = new ArrayList<Test>();
				exList = testC.getTestListByCourseSubject(msgGel.getCourseID(),msgGel.getSubjectID());
				client.sendToClient(exList);
			}
			break;
			
			case MESSAGE_EXECUTE_EXAMS_BY_COURSEID:
			{
				MessageExcuteExamByCourseID msgGel = (MessageExcuteExamByCourseID)baseMessage;
				 ExecuteTestControl etc=new ExecuteTestControl();
				 List<ExecuteTest> list = new ArrayList<ExecuteTest>();
				 list=etc.getExecuteTestListByCourseID(msgGel.courseID);
				 client.sendToClient(list);	
				
			}
			break;
			
			case MESSAGE_CHEATERS_CHECK:
			{
				MessageCheatersCheck MsgCc = (MessageCheatersCheck) baseMessage;
				ApprovingComputerizedTestGrade actg = new ApprovingComputerizedTestGrade(MsgCc.getTeacherID());
				List<Cheaters> cList = actg.checkCheaters();
				MessageCheatersCheckReply reply = new MessageCheatersCheckReply(cList);
				client.sendToClient(reply);
			}
			break;
			case MESSAGE_STUDENT_IN_COURSE:
			{
				MessageStudentInCourse  MsgSc = (MessageStudentInCourse ) baseMessage;
				StudentControl studentC= new StudentControl();
				List <Student> sList = studentC.getStudentListByCourseID(MsgSc.getCourseId(), MsgSc.getYear(), MsgSc.getSemester()) ;
				client.sendToClient(sList);
			}
			break;
			case MESSAGE_ALLOCATE_EXECUTE_TEST:
			{
			MessageAllocateExecuteTesT  MsgSc = (MessageAllocateExecuteTesT ) baseMessage;
			ExecuteTestControl tExecuteC= new ExecuteTestControl();
			String executeID = tExecuteC.AllocationExcuteExam(MsgSc.getExecuteTest()) ;
			client.sendToClient(executeID);
			}
			break;
			case MESSAGE_GET_NEW_TEACHER_REQUESTS:
			{
				 ExecuteTestControl tr=new ExecuteTestControl();
				 List<TeacherReqeust> list = new ArrayList<TeacherReqeust>();
				 list=tr.getNewTeacherRequestList();
				 client.sendToClient(list);	
				
			}
			break;
			case MESSAGE_REQUEST_TIME_EXTENTION:
			{
				MessageSendTimeExtentionRequest  MsgSter = (MessageSendTimeExtentionRequest) baseMessage;
				if (JDBC.existStatment(MsgSter.getTestID(), "executeTestID", "teacherrequest")){
					client.sendToClient("An extention request for this test already exist");
					return;
				}
				TeacherControl tc = new TeacherControl();
				tc.addTeacherRequest(MsgSter.getTimeAdd(), MsgSter.getReasonAdd(), MsgSter.getTestID(), MsgSter.getUserLog());
				client.sendToClient("Request Sent");
			}
			break;
			case MESSAGE_REQUEST_DECISION:
			{
				MessageRequestDecision MsgRD = (MessageRequestDecision)baseMessage;
				ExecuteTestControl etc = new ExecuteTestControl();
				etc.updateTeacherReqeust(MsgRD.getExecuteTestID(), MsgRD.getDecision(),MsgRD.getextraTime());	
			}
			break;
			
			case MESSAGE_ALLOCATE_EXECUTE_INFO:
			{
				MessageAllocateExecuteTesTInfo  MsgSter = (MessageAllocateExecuteTesTInfo) baseMessage;
				 ExecuteTestControl tr=new ExecuteTestControl();
				 String str = new String ();
				 str=tr.AllocationExcuteExamInfo(MsgSter.getExecuteTestInfo());
				 client.sendToClient(str);		
			}
			break;
			case MESSAGE_STATISTICS_LIST_BY_EXECUTED_TEST_LIST:
			{
			MessageStatisticInfoListByExecuteTestList  MsgSET = (MessageStatisticInfoListByExecuteTestList) baseMessage;
			ExecuteTestControl exc= new ExecuteTestControl();
			List<StatisticTestInformation> stiList = new ArrayList<StatisticTestInformation>();
			StatisticTestInformation sti;
			for(int i = 0; i<MsgSET.getListExecuteTest().size();i++){

				sti = exc.getStaticTestInformationByExecuteTestID(MsgSET.getListExecuteTest().get(i).getExecuteTestID());
				stiList.add(sti);
			}
			client.sendToClient(stiList);
			}
			break;
			
			case MESSAGE_GET_ALL_STUDENTS:
			{
				StudentControl sc = new StudentControl();
				List<Student> sList;
				sList = sc.getStudentList();
				client.sendToClient(sList);
			}
			break;
			
			case MESSAGE_GET_WORD_FILE:
			{
				MessageGetWordFile MsgGwf = (MessageGetWordFile) baseMessage;
				String path = MsgGwf.getExecuteTest().getWordTestPath();
				SendFileToClient sftc = new SendFileToClient(path);
				MyFile myfile =sftc.sendFileToClient();
				client.sendToClient(myfile);
			}
			break;
			
			case MESSAGE_SEND_WORD_FILE:
			{
				MessageSendWordTest MsgGwf = (MessageSendWordTest) baseMessage;
				GetFileFromClient gffc = new GetFileFromClient("Execute Test");
				String path = gffc.getFileFromClient(MsgGwf.getMyFile(),MsgGwf.getExecuteTest(),MsgGwf.getStudent());
				ExecuteExamByStudent eebs = new ExecuteExamByStudent(MsgGwf.getExecuteTest().getExecuteTestID(), MsgGwf.getStudent().getUserID());
				eebs.saveManualTest(path);
				
			}
			break;
			
			case MESSAGE_GET_STUDENT_WORD_FILE:
			{
				MessageGetStudentWordFile MsgGswf = (MessageGetStudentWordFile) baseMessage;
				SendFileToClient sftc = new SendFileToClient(MsgGswf.getPath());
				MyFile myFile = sftc.sendFileToClient();
				client.sendToClient(myFile);
			}
			break;
			
			case MESSAGE_FINAL_GRADE_MANUAL:
			{
				MessageFinalGrade MsgFg = (MessageFinalGrade) baseMessage;
				GetFileFromClient gffc = new GetFileFromClient("Execute Test");
				String path = gffc.getFileFromClient(MsgFg.getMyFile(), MsgFg.getApprovingGrade().getExecuteTest(),MsgFg.getApprovingGrade().getStudentInTest().getStudent());
				ApprovingComputerizedTestGrade aptg = new ApprovingComputerizedTestGrade(MsgFg.getApprovingGrade());
				aptg.updateFinalGradeManual(path);
				aptg.setStatisticInformation();
			}
			break;
			case MESSAGE_ALLOCATE_MANUAL_TEST:
			{
				MessageAllocateManualTest MsgAmt = (MessageAllocateManualTest) baseMessage;
				setFileFromClient sffc=new setFileFromClient(MsgAmt.getManualTest().getPath());
				String path = sffc.setFileFromClient(MsgAmt);
				MsgAmt.getManualTest().setPath(path);
				TestControl testC=new TestControl();
				String testId=testC.AllocationManual(MsgAmt.getManualTest());
				client.sendToClient(testId);
			}
			break;
			case MESSAGE_GET_PATH_MANUAL_EXAM:
				MessageGetManualByTestID MsgGmI=(MessageGetManualByTestID) baseMessage;
				TestControl testC=new TestControl();
				ManualTest manualTest=testC.ManualTestbyTestID(MsgGmI.getTestID());
				client.sendToClient(manualTest);
			}
				
	}
}





